
import {
	getStorageWidthSex
} from '@/common/request/storageSyncData.js'
export default {
	
	
	//  初始化页面数据
	async initPageData(){
		
		var _this = this; 
		await _this.geCateInfoListData();
		this.$refs.paging.reload()
		
		
	},

	menuItemClick(e,item) {


		for (var i = 0; i < this.menuListDatas.length; i++) {

			var menuItem = this.menuListDatas[i];
			if (i == e) {
				menuItem.sqlState = true
			} else {
				menuItem.sqlState = false
			}

		}
		this.cateCode = item.cateCode;
		this.$refs.paging.reload()


	},
	async queryList(pageNo, pageSize) {

		var _this = this;
		_this.pageNo = pageNo;
		_this.pageSize = pageSize;
		// console.log(pageNo,pageSize);
		
		
		if(_this.menuListDatas.length <1){
			await _this.getCateItemDetailData();
		}
		if(_this.menuListDatas.length <1){
			_this.$refs.paging.complete([])
		}else{
			this.getCateItemDetailData();
		}
		
		
	},
	enterBookInfoDetail(e){
		var bookInfoStr = JSON.stringify(e);
		uni.navigateTo({
			url: '/pages/baseBusiness/bookInfoDetail/bookInfoDetailView?bookInfo='+bookInfoStr
		})
	},
	async geCateInfoListData(){
		
		var that = this;
		var param = {
			cateGender:getStorageWidthSex().id,
		}
		that.menuListDatas  = [];
		
		console.log(param,"<------------------hahahahahh")
		
	   var res = await that.$api.getCateInfoList(param);
	   console.log(res,"11111<------------------hahahahahh")
	   if(res.data.code == 200){
	   	that.menuListDatas = res.data.rows
	   	that.menuListDatas.forEach((item,index) => {
	   	 if(index == 0){
	   		 item.sqlState = true;
	   		 that.cateCode = item.cateCode;
	   	 }else{
	   		 item.sqlState = false;
	   	 }
	   	})
		return
	   }else{
	   	return
	   }
	},
	
	async getCateItemDetailData(){
		var that = this;
		var localHttp = that.$http_url.getHttpUrl();
		var param = {
			info:{
				pageNum:that.pageNo,
				pageSize:that.pageSize
			},
			code:this.cateCode
		}
		
		var dataRes = await this.$sqlDBConfig.selectCollectionTableData2()
		that.$api.getCateItemDetail(param).then(res => {
			if(res.statusCode == 200){
				var bookList = res.data.rows;
				// console.log(bookList,"<--------------------")
				bookList.forEach(function(item, index) {
				      item.bookIconUrl = localHttp+"/images/"+item.bookCode+"/"+item.bookPic;
					  item.isCollection = false
					  dataRes.forEach(function(item1, index1) {
							  if(item1.bookcode == item.bookCode){
								   item.isCollection = true
							  }
					  })
				})
				that.$refs.paging.complete(bookList)
				
			}else{
				
			}
		}).catch(error => {
			
		})
	}

}
